package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author huanghui
 * @since 2023-07-20
 */
@RestController
@RequestMapping("lessons")
@Api(tags = "我的课程相关接口")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService lessonService;

    /** @author ZXX-挚爱
    * @Description
    * @Dete 16:37 2023/7/21
    * @Param [query]
    * @return com.tianji.common.domain.dto.PageDTO<com.tianji.learning.domain.vo.LearningLessonVO>
    **/

    @GetMapping("/page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery query){

        return lessonService.queryMyLessons(query);
    }

    /** @author ZXX-挚爱
    * @Description 查询正在学习的课程
    * @Dete 16:37 2023/7/21
    * @Param []
    * @return com.tianji.learning.domain.vo.LearningLessonVO
    **/

    @GetMapping("/now")
    @ApiOperation("查询正在学习的课程")
    public LearningLessonVO queryMyCurrentLesson (){
        return lessonService.queryMyCurrentLesson();
    }

    /** @author ZXX-挚爱
    * @Description 根据课程Id查询指定课程的学习状态
    * @Dete 16:37 2023/7/21
    * @Param [courseId]
    * @return com.tianji.learning.domain.vo.LearningLessonVO
    **/

    @GetMapping("/{courseId}")
    @ApiOperation("根据课程Id查询指定课程的学习状态")
    public LearningLessonVO queryMyLessonStatusById(
            @ApiParam(value = "课程Id",example = "1") @PathVariable Long courseId){
        return  lessonService.queryMyLessonStatusById(courseId);
    }

    /** @author ZXX-挚爱
    * @Description 根据课程Id删除课程
    * @Dete 16:36 2023/7/21
    * @Param [courseId]
    * @return void
    **/

    @DeleteMapping("/{courseId}")
    @ApiOperation("根据课程Id删除课程")
    public void deleteMyLessonByCourseId(
            @ApiParam(value = "课程Id",example = "1") @PathVariable Long courseId){
            lessonService.deleteMyLessonByCourseId(null,courseId);
    }

    /** @author ZXX-挚爱
    * @Description 检查课程是否有效
    * @Dete 16:42 2023/7/21
    * @Param [courseId]
    * @return java.lang.Long
    **/

    @ApiOperation("检查课程是否有效")
    @GetMapping("{courseId}/valid")
   public Long isLessonValid(
            @ApiParam(value = "课程Id",example = "1")
           @PathVariable  Long courseId ){
        return lessonService.isLessonValid(courseId);
   }
   /** @author ZXX-挚爱
   * @Description 统计课程的学习人数
   * @Dete 19:08 2023/7/21
   * @Param [courseId]
   * @return java.lang.Integer
   **/

    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程的学习人数")
    public  Integer countLearningLessonByCourse(
            @ApiParam(value = "课程Id",example = "1")
            @PathVariable("courseId") Long courseId){
        return lessonService.countLearningLessonByCourse(courseId);
    }

    @ApiOperation("创建学习计划接口")
    @PostMapping("/plans")
    public  void  createLearningPlans(@Valid @RequestBody LearningPlanDTO planDTO){
        lessonService.createLearningPlans(planDTO.getCourseId(),planDTO.getFreq());
    }

    @ApiOperation("查询本人的学习计划")
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery){
        return  lessonService.queryMyPlans(pageQuery);
    }
}
